package com.lemontree.spring.model;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

public class User {
    private String userName ="AAA";
    private Integer age = 12;
    private String password;

    public User() {
    }

    public User(String userName, Integer age) {
        this.userName = userName;
        this.age = age;
    }

    synchronized public void setValue(String userName,Integer age){
        this.userName = userName;
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        this.age = age;
    }

    public void getValue(){
        System.out.println("name: "+this.userName+" - age: "+this.age);
    }
    public User(String userName, Integer age, String password) {
        this.userName = userName;
        this.age = age;
        this.password = password;
    }

    public void add(String userName) {
        int num = 0;
        try {

            if (userName.equals("a")) {
                num = 100;
                System.out.println("this is a's num ");
                Thread.sleep(2000);
                System.out.println(" num is " + num);
            } else {
                num = 200;
                System.out.println("this is b's num");
                Thread.sleep(2000);
                System.out.println("num is " + num);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    private void sayHello() {
        System.out.println("hello reflect world!");
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }
}
